package hkr.se1.budgetapp;

import java.util.List;

import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class BudgetFragment extends Fragment {

	private MainActivity activity;

	public void onStart() {
		super.onStart();
		setTextViews();
	}

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		this.activity = (MainActivity) activity;

	}

	@Override
	public void onResume() {
		super.onResume();
		setTextViews();
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// Inflate the layout for this fragment
		return inflater.inflate(R.layout.budget_layout, container, false);
	}

	public void setTextViews() {
		TextView foodView = (TextView) activity.findViewById(R.id.foodView);
		TextView transportationView = (TextView) activity
				.findViewById(R.id.transportationView);
		TextView clothesView = (TextView) activity
				.findViewById(R.id.clothesView);
		TextView hobbyView = (TextView) activity.findViewById(R.id.hobbyView);
		int food = 0;
		int transportation = 0;
		int clothes = 0;
		int hobby = 0;
		List<Entry> entries = activity.EDS.getAllEntries();
		for (int i = 0; i < entries.size(); i++) {
			Entry temp = entries.get(i);
			String category = temp.getCategory();
			if (category != "Income") {
				if (category.equals("Food")) {
					food = food - temp.getAmount();
				} else if (category.equals("Transportation")) {
					transportation = transportation - temp.getAmount();
				} else if (category.equals("Clothes")) {
					clothes = clothes - temp.getAmount();
				} else if (category.equals("Hobby")) {
					hobby = hobby - temp.getAmount();
				}
			}
		}
		foodView.setText("Food: " + food + " kr");
		transportationView.setText("Transportation: " + transportation + " kr");
		clothesView.setText("Clothes: " + clothes + " kr");
		hobbyView.setText("Hobby: " + hobby + " kr");
	}
}